package MyCode.Swing.JPanelDemo;

import javax.swing.*;
import java.awt.*;

/**
 * 多种布局管理器的使用
 *
 * JPanel 是一般轻量级容器
 */
public class Gui5 extends JFrame{
    //定义组件
    JPanel jp1,jp2;
    JButton btn1,btn2,btn3,btn4,btn5,btn6;

    //构造方法
    public Gui5(){
        //创建组件
        //JPanel布局默认是FlowLayout
        jp1 = new JPanel();
        jp2 = new JPanel();

        btn1 = new JButton("Button1");
        btn2 = new JButton("Button2");
        btn3 = new JButton("Button3");
        btn4 = new JButton("Button4");
        btn5 = new JButton("Button5");
        btn6 = new JButton("Button6");

        //添加JPanel
        jp1.add(btn1);
        jp1.add(btn2);
        jp2.add(btn3);
        jp2.add(btn4);
        jp2.add(btn5);

        //把JPanel加入JFrame
        add(jp1, BorderLayout.NORTH);
        add(btn6,BorderLayout.CENTER);
        add(jp2,BorderLayout.SOUTH);

        //设置窗体
        setTitle("多种布局管理器的使用");
        setSize(300,300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);



    }

    public static void main(String[] args) {
        new Gui5();
    }

}
